package samsung.other;

/**
 * Class describe the situation of some object on the area.
 *
 * @author Vitaliy Muzalevskiy
 */
public class Position {
    
    private final int x;
    private final int y;

    public Position(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 23 * hash + this.x;
        hash = 23 * hash + this.y;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Position other = (Position) obj;
        if (this.x != other.x) {
            return false;
        }
        if (this.y != other.y) {
            return false;
        }
        return true;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }
    
    /**
     * @return <code>Position</code> value that situated on North against 
     * current position.
     */
    public Position getPositionUp(){
        return new Position(x, y + 1);
    }
    
    /**
     * @return <code>Position</code> value that situated on South against 
     * current position.
     */
    public Position getPositionDown(){
        return new Position(x, y - 1);
    }
    
    /**
     * @return <code>Position</code> value that situated on West against 
     * current position.
     */
    public Position getPositionLeft(){
        return new Position(x - 1, y);
    }
    
    /**
     * @return <code>Position</code> value that situated on East against 
     * current position.
     */
    public Position getPositionRight(){
        return new Position(x + 1, y);
    }

    @Override
    public String toString() {
        return "Position{" + "x=" + x + ", y=" + y + '}';
    }

    
}
